package com.candy.service.impl;

import com.candy.bean.UserInfo;
import com.candy.dao.UserInfoMapper;
import com.candy.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserInfoServiceImpl implements UserInfoService {
    @Autowired
    UserInfoMapper userInfoMapper;
    @Override
    public List<UserInfo> getUserInfoes(UserInfo userinfo) {
        return userInfoMapper.getUserInfoes(userinfo);
    }

    /**
     * 在后端进行判断，根据用户是否传递了id值，进行判断是新增还是修改
     * @param userinfo
     */
//    @Override
//    public void editUserInfo(UserInfo userinfo) {
//        Integer userid=userinfo.getId();
//        if(userid!=null){
//            userInfoMapper.updateByPrimaryKeySelective(userinfo);
//        }else{
//        userInfoMapper.insertSelective(userinfo);
//        }
//    }

    /**
     * 只处理新增功能
     * @param userinfo
     */
    @Override
    public void editUserInfo(UserInfo userinfo) {
        userInfoMapper.insertSelective(userinfo);
    }

    /**
     * 只处理修改方法
     * @param userinfo
     */
    @Override
    public void updateUserInfo(UserInfo userinfo) {
        userInfoMapper.updateByPrimaryKeySelective(userinfo);
    }

    @Override
    public void deleteUserInfo(Integer userid) {
        userInfoMapper.deleteByPrimaryKey(userid);
    }
}
